<template>
	<view v-if="showPopup">
		<view class="mask" @click="close" @touchmove.prevent></view>
		<view class="popup-task" :style="{ transform: `translateY(${showContent ? 0 : '100%'})` }">
			<view class="popup-task-header">
				<text class="title">任务详情</text>
				<view class="close" @click="close"></view>
			</view>
			<view class="popup-task-content">
				<view class="task-item" v-for="(item, index) in list" :key="index">
					<view class="bar">
						<view class="bar-title">{{ item.actionName }}</view>
						<view class="progress"><view class="progress-inner" :style="{ transform: `scaleX(${item.doneCount / item.actionCount})` }"></view></view>
						<view class="bar-tips">
							<text>进度</text>
							<text>{{ item.doneCount }}/{{ item.actionCount }}</text>
						</view>
					</view>
					<button @click="toFinish(item)" class="finish" :class="{ unfinish: item.isDone === 0 }">{{ item.isDone === 0 ? '进行中' : '已完成' }}</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'PopupTask',
	props: {},
	data() {
		return {
			showPopup: false,
			showContent: false,
			acceptTask: '',
			list: []
		};
	},
	methods: {
		/**
		 * 点击确认按钮
		 */
		open(list, acceptTask) {
			this.list = list || [];
			this.acceptTask = acceptTask;
			this.showPopup = true;
			setTimeout(r => {
				this.showContent = true;
			}, 16.7);
		},
		/**
		 * 点击取消按钮
		 */
		close() {
			this.showContent = false;
			setTimeout(r => {
				this.showPopup = false;
			}, 200);
		},
		toFinish(item) {
			if (item.isDone === 1) {
				return;
			}
			item.acceptTask = this.acceptTask;
			this.$emit('toFinish', item);
			this.close();
		}
	}
};
</script>

<style lang="scss" scoped>
.mask {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.2);
	z-index: 10;
	transition: all 0.2s;
}
.popup-task {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	transform: translateY(100%);
	transition: transform 0.2s;
	z-index: 11;
	padding: 8rpx 40rpx 0 40rpx;
	background: #f7f7f7;
	max-height: 550rpx;
	border-radius: 12px 12px 0px 0px;
	display: flex;
	flex-direction: column;
	.popup-task-header {
		padding: 24rpx 0;
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #66645d;
		line-height: 50rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.close {
			width: 52rpx;
			height: 52rpx;
			position: relative;
			&::before,
			&::after {
				content: '';
				background-color: #66645d;
				position: absolute;
				width: 74rpx;
				height: 4rpx;
				border-radius: 4rpx;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%) scale(0.5) rotate(45deg);
			}
			// &::before {
			// 	transform: rotate(45deg) scale(0.5);
			// }
			&::after {
				transform: translate(-50%, -50%) rotate(-45deg) scale(0.5);
			}
		}
	}
	.popup-task-content {
		overflow-y: auto;
		.task-item {
			padding: 12rpx 24rpx;
			background: #ffffff;
			border-radius: 20rpx;
			margin-bottom: 24rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.bar {
				display: flex;
				flex-direction: column;
				flex-shrink: 0;
				flex-grow: 1;
				margin-right: 24rpx;
				.bar-title {
					font-size: 28rpx;
					font-weight: 500;
					color: #66645d;
					line-height: 40rpx;
					margin-bottom: 12rpx;
				}
				.progress {
					height: 10rpx;
					width: 100%;
					border-radius: 10rpx;
					margin-bottom: 8rpx;
					background-color: rgba(102, 100, 93, 0.2);
					.progress-inner {
						width: 100%;
						height: 8rpx;
						background-color: rgba(250, 204, 107, 1);
						transform: scaleX(0.5);
						transform-origin: left center;
					}
				}
				.bar-tips {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 22rpx;
					font-weight: 300;
					color: #66645d;
					line-height: 30rpx;
				}
			}
			button {
				margin: 0;
				padding: 0;
				width: 120rpx;
				height: 50rpx;
				border-radius: 12rpx;
				font-size: 24rpx;
				font-weight: 300;
				line-height: 50rpx;
				&.finish {
					background: rgba(102, 100, 93, 0.1);
					color: rgba(102, 100, 93, 0.3);
				}
				&.unfinish {
					color: #66645d;
					background: rgba(250, 204, 107, 0.5);
				}
			}
		}
	}
}
</style>
